﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class KeyboradInput : IUserInput
{
	//Variable
	[Header("键位设置")]
	public string keyUp;
	public string keyDown;
	public string keyLeft;
	public string keyRight;

	public string keyA;
	public string keyB;
	public string keyC;
	public string keyD;

	public string keyJUp;
	public string keyJDown;
	public string keyJRight;
	public string keyJLeft;

	public MyButton keya = new MyButton();
	public MyButton keyb = new MyButton();
	public MyButton keyc = new MyButton();
	public MyButton keyd = new MyButton();

	void Update () {
		keya.Tick(Input.GetKey(keyA));
		keyb.Tick(Input.GetKey(keyB));
		keyc.Tick(Input.GetKey(keyC));
		keyd.Tick(Input.GetKey(keyD));

		Jup = Input.GetAxis("Mouse Y");
		Jright = Input.GetAxis("Mouse X");
		targetDup = (Input.GetKey(keyUp) ? 1.0f : 0f) - (Input.GetKey(keyDown) ? 1.0f : 0f);
		targetDright = (Input.GetKey(keyRight) ? 1.0f : 0f) - (Input.GetKey(keyLeft) ? 1.0f : 0f);

		if(inputEnable == false)
		{
			targetDup = 0;
			targetDright = 0;
		}

		Dup = Mathf.SmoothDamp(Dup, targetDup, ref velocityDup, 0.1f);
		Dright = Mathf.SmoothDamp(Dright, targetDright, ref velocityDright, 0.1f);

		Vector2 tempDAxis = SquareToCircle(new Vector2(Dright, Dup));
		float Dright2 = tempDAxis.x;
		float Dup2 = tempDAxis.y;

		Dmag = Mathf.Sqrt((Dup2 * Dup2) + (Dright2 * Dright2));
		Dvec = Dright2 * transform.right + Dup2 * transform.forward;

		run = (keya.isPressing && !keya.isDelaying)||keya.isExtending;
		defence = keyd.isPressing;

		jump = keyb.onPressed;
		attack = keyc.onPressed;

	}

}
